package ngames.com.sushitv.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

import ngames.com.sushitv.AppApplication;
import ngames.com.sushitv.R;
import ngames.com.sushitv.action.ItemVideoListAction;
import ngames.com.sushitv.adapter.FavoriteAdapter;
import ngames.com.sushitv.base.BaseAction;
import ngames.com.sushitv.core.AppModel;
import ngames.com.sushitv.core.AppModelImpl;
import ngames.com.sushitv.entity.ItemVideo;


/**
 * Created by edmond on 16-8-11.
 */
public class FavorityActivity extends AppCompatActivity{
    private boolean isShow = false;
    private RecyclerView recyclerView;
    private RelativeLayout linearLayout;
    private FavoriteAdapter adapter;
    private ItemVideoListAction itemVideoListAction;
    private Button delBtn;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_favorite);
        itemVideoListAction=new ItemVideoListAction(this,null,null,1,R.id.recyclerView, 1,10);
        itemVideoListAction.onCreate();
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        linearLayout  = (RelativeLayout) findViewById(R.id.select_info);
        delBtn= (Button) findViewById(R.id.btn_favority_del);
        ArrayList<ItemVideo> videos = new ArrayList<>();
        videos.add(new ItemVideo());
        videos.add(new ItemVideo());
        videos.add(new ItemVideo());
        videos.add(new ItemVideo());
        videos.add(new ItemVideo());
        videos.add(new ItemVideo());
        videos.add(new ItemVideo());
        videos.add(new ItemVideo());
        videos.add(new ItemVideo());

        adapter = new FavoriteAdapter(this,videos);
        recyclerView.setAdapter(adapter);

        toolbar.setNavigationIcon(R.drawable.arrow_back);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        delBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (isShow) {
                    adapter.setHide();
                    linearLayout.setVisibility(View.GONE);
                    isShow = false;
                } else {
                    adapter.setShow();
                    linearLayout.setVisibility(View.VISIBLE);
                    isShow = true;
                }
            }
        });
    }



    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(isShow){
            adapter.setHide();
            linearLayout.setVisibility(View.GONE);
            isShow = false;
            return false;
        }
        return super.onKeyDown(keyCode, event);
    }

}
